<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.jieSuan.jieSuanDanMingXi"/><spring:message code="message.listForm.yiLiaoJiGou"/></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
 	
   
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.button.addDetail"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx }/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.jieSuanDan"/><spring:message code="message.jieSuan.guanLi"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.woDeJieSuanDan"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                 <div class="input">
                        <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" maxlength="100" />
                    	</div>
                    
                        <div class="textalign1"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput" id="drugCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" maxlength="100" />
                    	</div>
                    
                  <div class="textalign" >
                    <button id="selectWSJ"  type="button" class="btn btn-success btn-sm" onclick="gridSerch();"><spring:message code="message.button.seachSpacing"/></button>
                  </div>
            </div>
        </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		<div class=" box box-warning bottongroup">

			<button type="button" onclick="batchJoin();" class="btn btn-default btn-sm"><spring:message code="message.jieSuan.tianJiaSpacing"/></button>
			<a href="toSettlementFirstList.html" class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></a>

		</div>
    </section>

		<%@ include file="/WEB-INF/component/commonJS.jsp"%>
		<script type="text/javascript">
		
		 //加载页面光标在名字框内，位于第一个
		   $("#drugName").focus();
		   
		 //绑定回车    id="selectWSJ"  
		   $('#drugName,#drugCode').bind('keydown', function(event) {
		       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
		           $('#selectWSJ').click();
		       }
		   }); 
		 
		$(function () {
			jQuery("#gridlist").jqGrid({
    			url: "${ctx}/settlementFirst/getAddFirstDetailDataList.html?settlementId=${settlementId}",
    		    mtype: "POST",
    			datatype: "json",
    			autowidth: true,
    			shrinkToFit: false,
    			height: 310,
    			colNames:[
    			          '<spring:message code="message.jieSuan.zhiFuDanMingXi"/>id',
    			          '<spring:message code="message.jieSuan.jieSuanLeiXing"/>',
                          '<spring:message code="message.jieSuan.caiGouJia"/>',
                          '<spring:message code="message.jieSuan.daoHuoShuLiang"/>',
    			          '<spring:message code="message.jieSuan.zongJinE"/>',
    			          '<spring:message code="message.model.peiSongQiYe"/>ID',
                          '<spring:message code="message.model.peiSongQiYe"/>',
                          'drugId',
                          '<spring:message code="message.listForm.yaoPinBianMa"/>',
                           '<spring:message code="message.listForm.tongYongMing"/>',
                          '<spring:message code="message.listForm.jiXing"/>',
                          '<spring:message code="message.listForm.guiGe"/>',
                          '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
                          '<spring:message code="message.listForm.baoZhuangDanWei"/>',
                          '<spring:message code="message.listForm.caiZhi"/>',
                          '<spring:message code="message.listForm.shengChanQiYe"/>'
    			          ],
    		   	colModel:[
					{ name: 'transId', width:160,hidden:true,align:"center" ,sortable:false},
					{ name: 'bankAcctTransType', width:100,align:"center" ,sortable:false,
						formatter : function(val, opts,rowdata) {
							if (val == 1) {return "<spring:message code="message.jieSuan.caiGouDan"/>";} 
							else if (val == 2) {return "<spring:message code="message.jieSuan.tuiHuoDan"/>";}
						}},   
					{ name: 'proPrice', width:100, align:"right",sortable:false,
    					formatter : function(val, opts,rowdata) {
    						return formatAmount(val, opts,rowdata);
						}
    				},
    				{ name: 'recpCount', width:80, align:"center",sortable:false},
    				{ name: 'sumPrice', width:100, align:"right",sortable:false,
                        formatter : function(val, opts,rowdata) {
                            return formatAmount(val, opts,rowdata);
                        }
                    },
					{ name: 'delCompId', width:160,hidden:true,align:"center" ,sortable:false},
					{ name: 'delCompName', width:160,align:"left" ,sortable:false},     
					{ name: 'drugId', width:100,hidden:true,align:"center" ,sortable:false},
    				{ name: 'drugCode', width:180,align:"center" ,sortable:false},
    				{ name: 'drugName', width:160, align:"left",sortable:false},
    				{ name: 'formName', width:80, align:"center",sortable:false},
    				{ name: 'specName', width:80, align:"center",sortable:false},
    				{ name: 'factor', width:80, align:"center",sortable:false},
    				{ name: 'unit', width:60, align:"center",sortable:false},
    				{ name: 'materialName', width:60, align:"center",sortable:false},
    				{ name: 'compName', width:160, align:"left",sortable:false}
    				
    		   	],
    			 rowNum: 20,
    		     rowList: [10, 20, 50, 100],
    		     rownumbers: true,
    		     pager: "#gridpage",
    		     viewrecords: true,
    		     multiselect: true, 
    		     caption: "<spring:message code="message.jieSuan.jieSuanDanMingXi"/><spring:message code="message.listForm.lieBiao"/>",
    		   //序号宽度自动变化
                 gridComplete:function(){
                     //序号列宽度自适应（参数为jqgridID）
                     autoRNWidth("gridlist");
                     //数据只有一条时默认选中（参数为jqgridID）
                     selectByOneData("gridlist");
                 },
    		     jsonReader: {
    		         repeatitems: false,
    		         id: "ids"
    		     }
    		});
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
			
	
		//查询
        function gridSerch() {
        	var drugCode = $.trim($("#drugCode").val());
        	var drugName = $.trim($("#drugName").val());
        	var compName = $.trim($("#compName").val());
        	var submitEndDate = $.trim($("#submitEndDate").val());
        	var status = $.trim($("#status").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"drugCode":drugCode,
    	        		"drugName":drugName,
    	        		"compName":compName,
    	        		"submitEndDate":submitEndDate,
    	        		"status":status},
    	        		page:1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
		
      //添加
        function batchJoin(){
      	 
          	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
      		if (rowIds.length <= 0) {
      			$.HN.message.alert("请选择要添加的结算单！", "<spring:message code="message.HN.alert.type"/>", "warn");
      			return;
      		}
      		$.HN.message.confirm('<spring:message code="message.jieSuan.queDingJiaRuSuoXuanMa"/>', '', '').on(function (e) {
      			if (e) {
      				var list = [];
      	    		for (var i=0; i<rowIds.length; i++) {
      	    			rowId = rowIds[i];
      	    			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
      	    			list.push({"bankAcctTransInfoId":rowdata.transId}); 
      	    		}
      	    		$.post("${ctx}/settlementFirst/addFirstDetail.html", {
      	    			"array" : json.jsonToString(list),"settlementId":"${settlementId}"
      	    		}, function(result) {
      	    			if (result.success) {
      	    				gridSerch();
      	    				$.HN.message.alert("添加成功！", "<spring:message code="message.HN.alert.type"/>", "success");
      	    			} else {
      	    				if(result.code ==1){
      	    					batchJoin(1);
      	    				}
      	    				$.HN.message.alert(result.msg || "添加失败！", "<spring:message code="message.HN.alert.type"/>", "error");
      	    			}
      	    		}, "json")
      			}
      		});
          }
			 
</script>
</body>
</html>